package ui.scene
{
	import flash.display.DisplayObject;
	import flash.display.Scene;
	import flash.utils.Dictionary;

	import globals.Global;

	import util.DisplayUtil;
	import util.Logger;

	public class SceneManager
	{
		public var currentScene:IScene;

		public static const SCENES:Dictionary = new Dictionary();

		public function init():void
		{
			SCENES[BaseScene.GAME_SCENE] = new GameScene();
			SCENES[BaseScene.STAGE_SCENE] = new StageScene();
			SCENES[BaseScene.BATTLE_SCENE] = new BattleScene();
		}

		public function SceneManager()
		{
		}

		public function enter(type:uint):void
		{
			var scene:BaseScene = SCENES[type];

			if(scene == null)
			{
				Logger.error("scene not register");
				return;
			}

			if(currentScene != null)
			{
				currentScene.exit();
				DisplayUtil.removeChild(Global.game.sceneLayer, currentScene as DisplayObject);
			}
			currentScene = scene;
			scene.enter();
			DisplayUtil.addChild(currentScene as DisplayObject, Global.game.sceneLayer);

			//对faceLayer层做特殊处理。
			if(type == BaseScene.GAME_SCENE && Global.game.contains(Global.game.faceLayer))
			{
				DisplayUtil.addChildAt(Global.game.faceLayer, Global.game, 2);
			}
			else
			{
				DisplayUtil.removeChild(Global.game, Global.game.faceLayer);
			}
		}

		public function getCurrentScene():IScene
		{
			return currentScene;
		}

		public function getGameScene(type:uint):BaseScene
		{
			if(SCENES[type] != undefined)
			{
				return SCENES[type];
			}
			return null;
		}
	}
}